/**
 * @a https://leetcode.cn/problems/add-binary/
 */

#include "common.h"

class Solution {
public:
    string addBinary(string a, string b) {
        string ret;
        int cur1 = a.size() - 1, cur2 = b.size() - 1;
        int tmp = 0;
        while(cur1 >= 0 || cur2 >= 0 || tmp){
            if(cur1 >= 0) tmp += a[cur1--] - '0';
            if(cur2 >= 0) tmp += b[cur2--] - '0';
            ret.push_back((tmp % 2) + '0');
            tmp /= 2;
        }
        reverse(ret.begin(), ret.end());
        return ret;
    }
};